﻿using System;
using System.Runtime.Serialization;

namespace Crocodoc
{
    /// <summary>
    /// Represents a document's status returned by /document/status.
    /// </summary>
    [DataContract]
    public class DocumentStatus
    {
        /// <summary>
        /// Hack to get deserialization to work correctly.  You should use the Status property for checking.
        /// </summary>
        [DataMember]
        public string status;

        /// <summary>
        /// Gets or sets the error message. Only exists if the status is ERROR.
        /// </summary>
        [DataMember(Name="error")]
        public string Error
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets Document's unique identifier.
        /// </summary>
        [DataMember(Name = "uuid")]
        public string UUID
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the current state of the document.
        /// </summary>
        public DocumentStatusCode Status
        {
            get
            {
                if (String.IsNullOrEmpty(status))
                {
                    return DocumentStatusCode.Error;
                }
                return (DocumentStatusCode)Enum.Parse(typeof(DocumentStatusCode), status[0] + status.ToLower().Substring(1));
            }
        }

        /// <summary>
        /// Gets or sets whether or not the document is available for viewing.
        /// </summary>
        [DataMember(Name="viewable")]
        public bool Viewable
        {
            get;
            set;
        }
    }

    /// <summary>
    /// Represents a document status that could be returned by the Crocodoc server.
    /// </summary>
    public enum DocumentStatusCode
    {
        Queued,
        Processing,
        Done,
        Error
    }
}
